package algorithm;

/**
 * 27. 移除元素
 */
public class T00027 {
    public static void main(String[] args) {
        int[] nums = {4,5};
        int n = new Solution().removeElement(nums, 5);
        for (int i = 0; i < n; i++) {
            System.out.print(nums[i] + " ");
        }
    }

static class Solution {
    public int removeElement(int[] nums, int val) {
        if(nums == null)
            return -1;
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            while(nums[i] == val && i != n && n > 0)
                nums[i] = nums[-- n];
        }
        return n;
    }
}
}